package com.engine.update.cmd;

import com.alibaba.fastjson.JSONObject;
import com.engine.core.domain.GenTable;
import com.engine.core.gen.Mysql;
import com.engine.core.interceptor.JdbcCommandContext;
import com.engine.core.rowMapper.JdbcTypeBiz;
import com.engine.core.util.QueryUtil;
import com.engine.core.util.Response;
import com.engine.core.interceptor.ResponseCommand;
import com.engine.system.User;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.Map;

public class SaveMainAndDetailCommand extends ResponseCommand {
    public SaveMainAndDetailCommand(User user, Map<String, Object> params) {
        super(user, params);
    }

    /**
     * @param commandContext
     * @return
     * @throws Exception
     */
    @Override
    public Response execute(JdbcCommandContext commandContext) throws Exception {
        Response response=Response.static_success("执行成功!");
        String tableName=(String)params.get(QueryUtil.QUERY_TABLE);
        JdbcTemplate jdbcTemplate=commandContext.getJdbcTemplate();
        GenTable genTable= Mysql.getTable(tableName,jdbcTemplate);
        String datas=(String)params.get(QueryUtil.QUERY_CONTENT);
        Map<String,String> othersMap= JdbcTypeBiz.getUpdateOthersByContent(datas);
//        Map<String,String> joinMap= JdbcTypeBiz.getMapValueByAttr(datas,QueryUtil.SAVE_MAINDEtAIL_JOINS);
        Map<String,String> copyToMap=JdbcTypeBiz.getMapValueByAttr(datas,QueryUtil.SAVE_MAINDEtAIL_JOINS_COPYTO);
        String mainData= JSONObject.parseObject(datas).getJSONObject(QueryUtil.UPDATA_DATA).getString("main");
        


        return response;
    }
}
